home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol076 / modmprot.col < prev    next >
Encoding:
Text File  |  1987-01-14  |  7.5 KB  |  179 lines

  1.  
  2. MODEM PROTOCOL OVERVIEW  178 lines, 7.5K
  3.  
  4. 1/1/82 by Ward Christensen.  I will maintain a master copy of
  5. this.  Please pass on changes or suggestions via CBBS/Chicago
  6. at (312) 545-8086, or by voice at (312) 849-6279.
  7.  
  8. NOTE this does not include things which I am not familiar with,
  9. such as the CRC option implemented by John Mahr.
  10.  
  11. Last Rev: (none)
  12.  
  13. At the request of Rick Mallinak on behalf of the guys at
  14. Standard Oil with IBM P.C.s, as well as several previous
  15. requests, I finally decided to put my modem protocol into
  16. writing.  It had been previously formally published only in the
  17. AMRAD newsletter.
  18.  
  19.     Table of Contents
  20. 1. DEFINITIONS
  21. 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  22. 3. MESSAGE BLOCK LEVEL PROTOCOL
  23. 4. FILE LEVEL PROTOCOL
  24. 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  25. 6. PROGRAMMING TIPS.
  26.  
  27. -------- 1. DEFINITIONS.
  28. <soh>    01H
  29. <eot>    04H
  30. <ack>    05H
  31. <nak>    15H
  32. <can>   18H
  33.  
  34. -------- 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  35. Asynchronous, 8 data bits, no parity, one stop bit.
  36.  
  37.     The protocol imposes no restrictions on the contents of the
  38. data being transmitted.  No control characters are looked for
  39. in the 128-byte data messages.  Absolutely any kind of data may
  40. be sent - binary, ASCII, etc.  The protocol has not formally
  41. been adopted to a 7-bit environment for the transmission of
  42. ASCII-only (or unpacked-hex) data , although it could be simply
  43. by having both ends agree to AND the protocol-dependent data
  44. with 7F hex before validating it.  I specifically am referring
  45. to the checksum, and the block numbers and their ones-
  46. complement.
  47.     Those wishing to maintain compatibility of the CP/M file
  48. structure, i.e. to allow modemming ASCII files to or from CP/M
  49. systems should follow this data format:
  50.   * ASCII tabs used (09H); tabs set every 8.
  51.   * Lines terminated by CR/LF (0DH 0AH)
  52.   * End-of-file indicated by ^Z, 1AH.  (one or more)
  53.   * Data is variable length, i.e. should be considered a
  54.     continuous stream of data bytes, broken into 128-byte
  55.     chunks purely for the purpose of transmission. 
  56.   * A CP/M "peculiarity": If the data ends exactly on a
  57.     128-byte boundary, i.e. CR in 127, and LF in 128, a
  58.     subsequent sector containing the ^Z EOF character(s)
  59.     is optional, but is preferred.  Some utilities or
  60.     user programs still do not handle EOF without ^Zs.
  61.   * The last block sent is no different from others, i.e.
  62.     there is no "short block".  
  63.  
  64. -------- 3. MESSAGE BLOCK LEVEL PROTOCOL
  65.  Each block of the transfer looks like:
  66. <SOH><blk #><255-blk #><--128 data bytes--><cksum>
  67.     in which:
  68. <SOH>       = 01 hex
  69. <blk #>     = binary number, starts at 01 increments by 1, and
  70.               wraps 0FFH to 00H (not to 01)
  71. <255-blk #> = blk # after going thru 8080 "CMA" instr, i.e.
  72.               each bit complemented in the 8-bit block number.
  73.               Formally, this is the "ones complement".
  74. <cksum>     = the sum of the data bytes only.  Toss any carry.
  75.  
  76. -------- 4. FILE LEVEL PROTOCOL
  77.  
  78. ---- 4A. COMMON TO BOTH SENDER AND RECEIVER:
  79.  
  80.     All errors are retried 10 times.  For versions running with
  81. an operator (i.e. NOT with XMODEM), a message is typed after 10
  82. errors asking the operator whether to "retry or quit".
  83.     Some versions of the protocol use <can>, ASCII ^X, to
  84. cancel transmission.  This was never adopted as a standard, as
  85. having a single "abort" character makes the transmission
  86. susceptible to false termination due to an <ack> <nak> or <soh>
  87. being corrupted into a <can> and canceling transmission.
  88.     The protocol may be considered "receiver driven", that is,
  89. the sender need not automatically re-transmit, although it does
  90. in the current implementations.
  91.  
  92. ---- 4B. RECEIVE PROGRAM CONSIDERATIONS:
  93.     The receiver has a 10-second timeout.  It sends a <nak>
  94. every time it times out.  The receiver's first timeout, which
  95. sends a <nak>, signals the transmitter to start.  Optionally,
  96. the receiver could send a <nak> immediately, in case the sender
  97. was ready.  This would save the initial 10 second timeout. 
  98. However, the receiver MUST continue to timeout every 10 seconds
  99. in case the sender wasn't ready.
  100.     Once into a receiving a block, the receiver goes into a
  101. one-second timeout for each character and the checksum.  If the
  102. receiver wishes to <nak> a block for any reason (invalid
  103. header, timeout receiving data), it must wait for the line to
  104. clear.  See "programming tips" for ideas
  105.     Synchronizing:  If a valid block number is received, it
  106. will be: 1) the expected one, in which case everything is fine;
  107. or 2) a repeat of the previously received block.  This should
  108. be considered OK, and only indicates that the receivers <ack>
  109. got glitched, and the sender re-transmitted; 3) any other block
  110. number indicates a fatal loss of synchronization, such as the
  111. rare case of the sender getting a line-glitch that looked like
  112. an <ack>.  Abort the transmission, sending a <can>
  113.  
  114. ---- 4C. SENDING PROGRAM CONSIDERATIONS.
  115.  
  116.     While waiting for transmission to begin, the sender has
  117. only a single very long timeout, say one minute.  In the
  118. current protocol, the sender has a 10 second timeout before
  119. retrying.  I suggest NOT doing this, and letting the protocol
  120. be completely receiver-driven.  This will be compatible with
  121. existing programs.
  122.     When the sender has no more data, it sends an <eot>, and
  123. awaits an <ack>, resending the <eot> if it doesn't get one. 
  124. Again, the protocol could be receiver-driven, with the sender
  125. only having the high-level 1-minute timeout to abort.
  126.  
  127.  
  128. -------- 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  129.  
  130. Here is a sample of the data flow, sending a 3-block message.
  131. It includes the two most common line hits - a garbaged block,
  132. and an <ack> reply getting garbaged.  <xx> represents the
  133. checksum byte.
  134.  
  135. SENDER                    RECEIVER
  136.                 times out after 10 seconds,
  137.             <---        <nak>
  138. <soh> 01 FE -data- <xx>    --->
  139.             <---        <ack>
  140. <soh> 02 FD -data- xx    --->    (data gets line hit)
  141.             <---        <nak>
  142. <soh> 02 FD -data- xx    --->
  143.             <---        <ack>
  144. <soh> 03 FC -data- xx    --->
  145.    (ack gets garbaged)    <---        <ack>
  146. <soh> 03 FC -data- xx    --->        <ack>
  147. <eot>            --->
  148.             <---        <ack>
  149.  
  150. -------- 6. PROGRAMMING TIPS.
  151.  
  152. * The character-receive subroutine should be called with a
  153. parameter specifying the number of seconds to wait.  The
  154. receiver should first call it with a time of 10, then <nak> and
  155. try again, 10 times.
  156.   After receiving the <soh>, the receiver should call the
  157. character receive subroutine with a 1-second timeout, for the
  158. remainder of the message and the <cksum>.  Since they are sent
  159. as a continuous stream, timing out of this implies a serious
  160. like glitch that caused, say, 127 characters to be seen instead
  161. of 128.
  162.  
  163. * When the receiver wishes to <nak>, it should call a "PURGE"
  164. subroutine, to wait for the line to clear.  Recall the sender
  165. tosses any characters in its UART buffer immediately upon
  166. completing sending a block, to ensure no glitches were mis-
  167. interpreted.
  168.   The most common technique is for "PURGE" to call the
  169. character receive subroutine, specifying a 1-second timeout,
  170. and looping back to PURGE until a timeout occurs.  The <nak> is
  171. then sent, ensuring the other end will see it.
  172.  
  173. * You may wish to add code recommended by Jonh Mahr to your
  174. character receive routine - to set an error flag if the UART
  175. shows framing error, or overrun.  This will help catch a few
  176. more glitches - the most common of which is a hit in the high
  177. bits of the byte in two consecutive bytes.  The <cksum> comes
  178. out OK since counting in 1-byte produces the same result of
  179. adding 80H + 80H as with adding 00H + 00H.
  180.